﻿using System.Collections.Generic;
using Engine;

namespace Mekiasm
{
    public class AnimateBlockSystem
    {
        public static List<Common.AnimateBlockItem> AnimateBlockItems = new List<Common.AnimateBlockItem>();
        public static double FrameDuration = 1 / (double)60;

        public static void Add(Common.AnimateBlockItem animateBlock)
        {
            Common.AnimateBlockItem animate = AnimateBlockItems.Find(p => p.x == animateBlock.x && p.y == animateBlock.y && p.z == animateBlock.z);
            if (animate == null) AnimateBlockItems.Add(animateBlock);
            else
            {
                AnimateBlockItems.Remove(animate);
                AnimateBlockItems.Add(animateBlock);
            }
        }
        public static bool Get(Point3 point, out Common.AnimateBlockItem animate)
        {
            animate = AnimateBlockItems.Find(p => p.x == point.X && p.y == point.Y && p.z == point.Z);
            return animate != null;
        }

        public static void Remove(int x, int y, int z)
        {
            Common.AnimateBlockItem animate = AnimateBlockItems.Find(p => p.x == x && p.y == y && p.z == z);
            if (animate != null) AnimateBlockItems.Remove(animate);
        }

        public static void Update()
        {
            for (int i = 0; i < AnimateBlockItems.Count; i++)
            {
                AnimateBlockItems[i].Next();
            }
        }
        public static void Dispose()
        {
            AnimateBlockItems.Clear();
        }



    }
}
